package com.tanhua.server.controller;

import com.tanhua.server.service.TanhuaService;
import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ck
 * @date 2021/11/12 14:32
 */

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {


    @Autowired
    private TanhuaService tanhuaService;
    /**
     * 今日佳人
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        TodayBest todayBest = tanhuaService.getFirst();
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查询分页推荐好友列表
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto recommendUserDto){
        PageResult pageResult = tanhuaService.recommendation(recommendUserDto);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查看佳人详情
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId){
        TodayBest todayBest = tanhuaService.findPersonalInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查看陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String question = tanhuaService.findQuestion(userId);
        return ResponseEntity.ok(question);
    }

    /**
     * 回复陌生人问题
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map){
        String obj = map.get("userId").toString();
        Long userId = Long.valueOf(obj);
        String reply = (String) map.get("reply");
        tanhuaService.replyQuestion(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花-推荐用户列表
     */
    @GetMapping("/cards")
    public ResponseEntity queryCardsList() {
        List<TodayBest> list = tanhuaService.queryCardsList();
        return ResponseEntity.ok(list);
    }

    /**
     * 右滑喜欢
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long likeUserId){
        tanhuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 左滑不喜欢
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long likeUserId){
        tanhuaService.unlikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜索附近的人
     */
    @GetMapping("/search")
    public ResponseEntity search(@RequestParam("gender") String gender,
                                 @RequestParam(value = "distance",defaultValue = "2000") String distance){
        List<NearUserVo> vo = tanhuaService.search(gender,distance);
        return ResponseEntity.ok(vo);
    }
}
